package kr.hkit.powerjava.chapter23;

import java.awt.Font;
import java.awt.HeadlessException;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class CountDownTest extends JFrame{
	private JLabel label;	//글짜표현
	
	class MyThread extends Thread {
		
		public MyThread() {
			this.start();
		}
		
		@Override
		public void run() {
			for (int i = 20; i > 0; i--) {
				try {Thread.sleep(1000);	} catch (InterruptedException e) {}
				label.setText(i + "");
			}
		}
	}
	
	public CountDownTest() throws HeadlessException {
		setTitle("카운트다운");
		setSize(300,200);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	//종료됨
		label = new JLabel("Start");
		label.setFont(new Font("Serif", Font.BOLD, 100));	//폰트 조절
		add(label);
		
		Thread t = new MyThread();	//MyThread 생성자 호출
		setVisible(true);	//jfame 활성화
		while(t.isAlive()); //숫자가 계속 돌고 있음. 쓰레드가 끝나면 종료
		System.exit(0); //정상종료
	}
	
	public static void main(String[] args) {
		new CountDownTest();
	}
}